// Avoid multiple header inclusion
#ifndef TIMEDATE_H
#define TIMEDATE_H
 
// Include the basics
#include <ktexteditor/plugin.h>
#include <ktexteditor/view.h>
#include <kxmlguiclient.h>
#include <klocalizedstring.h>
#include <kpluginfactory.h>

#include <QtCore/QEvent>
#include <QtCore/QObject>
#include <QtCore/QList>
#include <QtCore/QVariantList>


/**
  * Variable that will contain the localized time & date format
  * at the beginning.
  */
static QString pathKickass = QString();
static QString gkOptions    = "-vicesymbols";
static QString gvOptions    = "x64 -moncommand %b.vs %b.prg";
static QString gtOptions    = "konsole -workdir %p -e %e";
static bool    gTerminal    = true;

class KAction;
class KProcess;
/**
  * This is the plugin class. There will be only one instance of this class.
  * We always want to inherit KTextEditor::Plugin here.
  */
class KickassPlugin
  : public KTextEditor::Plugin
{
	Q_OBJECT
  public:
    // Constructor
    explicit KickassPlugin(QObject *parent,
                            const QVariantList &args);
    // Destructor
    virtual ~KickassPlugin();
    
    static KickassPlugin *self() { return plugin; }
 
    // Overriden methods
    // This method is called when a plugin has to be added to a view. As there
    // is only one instance of this plugin, but it is possible for plugins to
    // behave in different ways in different opened views where it is loaded, in
    // Kate plugins are added to views. For that reason we have the plugin itself
    // (this class) and then the plugin view class.
    // In this methods we have to create/remove KickassPluginView classes.
    void addView (KTextEditor::View *view);
    void removeView (KTextEditor::View *view);
 
    void readConfig();
    void writeConfig();

    virtual void readConfig (KConfig *) {}
    virtual void writeConfig (KConfig *) {}
    	

    void setkOptions(const QString &opts);
    QString kOptions() const {return m_kOptions;}
    
    void setvOptions(const QString &opts);
    QString vOptions() const {return m_vOptions;}
    
    void settOptions(const QString &opts);
    QString tOptions() const {return m_tOptions;}
    
    void setTerminal(const bool on);
    bool terminal() const {return m_terminal;}
    	
    void setPath(const QString &path);
    QString path() const {return m_path;}
  private:
    static KickassPlugin *plugin;
    QList<class KickassPluginView*> m_views;
    bool m_autoBrackets;
    bool m_autoQuotations;
    QString m_path;
    QString m_kOptions;
    QString m_vOptions;
    QString m_tOptions;
    bool m_terminal;
};
 
K_PLUGIN_FACTORY_DECLARATION(KickassPluginFactory)

/**
  * This is the plugin view class. There can be as much instances as views exist.
  */
class KickassPluginView
   : public QObject, public KXMLGUIClient
{
  Q_OBJECT
 
  public:
    explicit KickassPluginView(QString path,QString kopts,QString vopts,QString topts,bool bTerm,KTextEditor::View *view = 0);
    ~KickassPluginView();

    void setkOptions(const QString &opts) {m_kOptions=opts;}
    QString kOptions() const {return m_kOptions;}
    
    void setvOptions(const QString &opts) {m_vOptions=opts;}
    QString vOptions() const {return m_vOptions;}
    
    void settOptions(const QString &opts) {m_tOptions=opts;}
    QString tOptions() const {return m_tOptions;}
    
    void setPath(const QString &path) {m_path=path;}
    QString path() const {return m_path;}
    
    void setTerminal(const bool on) {m_terminal=on;}
    bool terminal() const {return m_terminal;}
    
  private Q_SLOTS:
    void slotAssembleNRun();
    void slotRun();
    void slotError();
 
  private:
    KTextEditor::View *m_view;
    QString m_path;
    QString m_kOptions;
    QString m_vOptions;
    QString m_tOptions;
    bool m_terminal;
    int	m_run;
    QString m_msgs;
    int m_errLine;
    KAction *m_errAction;
    KProcess *proc;
};
 
#endif // TIMEDATE_H